﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class ArraySort
    {
        public static void Demo01()
        {  
			int[] arr = { 3, 5, 55, 2, 666, 39 };
            Console.WriteLine("排序前的数组为:");
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i]+",");
            }
            Console.WriteLine();
            for (int i = 0; i < arr.Length; i++)
            {
                //比较次数
                for (int j = i; j > 0; j--)
                {
                    if (arr[j] < arr[j - 1])
                    {
                        int temp = arr[j];
                        arr[j] = arr[j - 1];
                        arr[j - 1] = temp;
                    }
                }
            }
            Console.WriteLine("排序后的数组为:");
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(+arr[i] + ",");
            }
        }
    }
}
